package com.yanqu.road.dao.impl.activity.hanghai;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.hanghai.config.HangHaiShipConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class HangHaiShipConfigDaoImpl extends TempDao {

    public static String getHangHaiShipConfigListSql = "select * from t_s_activity_hanghai_ship where activityId=? order by `level` asc";

    public List<HangHaiShipConfig> getHangHaiShipConfigList(int activityId) {
        List<HangHaiShipConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getHangHaiShipConfigListSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HangHaiShipConfig hangHaiShipConfig = new HangHaiShipConfig();
                hangHaiShipConfig.setActivityId(rs.getInt("activityId"));
                hangHaiShipConfig.setLevel(rs.getInt("level"));
                hangHaiShipConfig.setName(rs.getString("name"));
                hangHaiShipConfig.setIcon(rs.getString("icon"));
                hangHaiShipConfig.setAddition(rs.getInt("addition"));
                hangHaiShipConfig.setUpgradeCost(rs.getString("upgradeCost"));
                list.add(hangHaiShipConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

}
